package com.example.administrator.exkotlin.activity

import android.app.Activity
import android.util.Log

/**
 * 统一管理Activity
 * 方便一次性退出
 * */
object ActivityCollector {
    private val TAG = "ActivityCollector"
    private val Activities = ArrayList<Activity>()

    fun addActivity(activity: Activity) {
        Log.i(TAG, "addActivity ${activity.toString()}")
        Activities.add(activity)
    }

    fun removeActivity(activity: Activity) {
        //实际上Base传入的this和子类的this，都是同一个Activity
        if (Activities.contains(activity)) {
            Activities.remove(activity)
            activity.finish()
            Log.i(TAG, "After removeActivity ${Activities.size}")
        }
    }

    fun Quilt() {
        Log.i(TAG, "Quilt ${Activities?.size}")
        for (activity in Activities) {
            activity.finish()
        }
        android.os.Process.killProcess(android.os.Process.myPid())
    }
}